from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-04-17 14:09:51.917188
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 17, Apr, 2021
Time: 14:09:56
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.5788
Nobs: 264.000 HQIC: -48.3080
Log likelihood: 3159.92 FPE: 6.41926e-22
AIC: -48.7979 Det(Omega_mle): 4.59373e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.438277 0.124418 3.523 0.000
L1.Burgenland 0.082053 0.061289 1.339 0.181
L1.Kärnten -0.222182 0.053882 -4.124 0.000
L1.Niederösterreich 0.080161 0.133641 0.600 0.549
L1.Oberösterreich 0.210501 0.126589 1.663 0.096
L1.Salzburg 0.271704 0.069998 3.882 0.000
L1.Steiermark 0.121728 0.089132 1.366 0.172
L1.Tirol 0.120380 0.061378 1.961 0.050
L1.Vorarlberg -0.035240 0.056497 -0.624 0.533
L1.Wien -0.056761 0.114680 -0.495 0.621
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.478845 0.145059 3.301 0.001
L1.Burgenland 0.001899 0.071457 0.027 0.979
L1.Kärnten 0.329495 0.062821 5.245 0.000
L1.Niederösterreich 0.077701 0.155813 0.499 0.618
L1.Oberösterreich -0.067880 0.147591 -0.460 0.646
L1.Salzburg 0.223878 0.081611 2.743 0.006
L1.Steiermark 0.107742 0.103920 1.037 0.300
L1.Tirol 0.141242 0.071561 1.974 0.048
L1.Vorarlberg 0.154481 0.065870 2.345 0.019
L1.Wien -0.435451 0.133706 -3.257 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.280811 0.062515 4.492 0.000
L1.Burgenland 0.093773 0.030795 3.045 0.002
L1.Kärnten -0.017346 0.027074 -0.641 0.522
L1.Niederösterreich 0.064319 0.067150 0.958 0.338
L1.Oberösterreich 0.279880 0.063606 4.400 0.000
L1.Salzburg 0.026742 0.035171 0.760 0.447
L1.Steiermark 0.002852 0.044786 0.064 0.949
L1.Tirol 0.071071 0.030840 2.305 0.021
L1.Vorarlberg 0.082881 0.028387 2.920 0.004
L1.Wien 0.118853 0.057622 2.063 0.039
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.215124 0.060780 3.539 0.000
L1.Burgenland 0.022231 0.029941 0.742 0.458
L1.Kärnten 0.008449 0.026322 0.321 0.748
L1.Niederösterreich 0.051620 0.065286 0.791 0.429
L1.Oberösterreich 0.399452 0.061841 6.459 0.000
L1.Salzburg 0.083448 0.034195 2.440 0.015
L1.Steiermark 0.128725 0.043543 2.956 0.003
L1.Tirol 0.049784 0.029984 1.660 0.097
L1.Vorarlberg 0.084203 0.027600 3.051 0.002
L1.Wien -0.043017 0.056023 -0.768 0.443
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.495475 0.118644 4.176 0.000
L1.Burgenland 0.093878 0.058445 1.606 0.108
L1.Kärnten 0.011892 0.051381 0.231 0.817
L1.Niederösterreich 0.007125 0.127440 0.056 0.955
L1.Oberösterreich 0.129398 0.120715 1.072 0.284
L1.Salzburg 0.060193 0.066750 0.902 0.367
L1.Steiermark 0.063516 0.084996 0.747 0.455
L1.Tirol 0.212048 0.058530 3.623 0.000
L1.Vorarlberg 0.031743 0.053875 0.589 0.556
L1.Wien -0.098014 0.109358 -0.896 0.370
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187375 0.094282 1.987 0.047
L1.Burgenland -0.011189 0.046444 -0.241 0.810
L1.Kärnten -0.006440 0.040831 -0.158 0.875
L1.Niederösterreich 0.008127 0.101271 0.080 0.936
L1.Oberösterreich 0.407425 0.095927 4.247 0.000
L1.Salzburg 0.016929 0.053043 0.319 0.750
L1.Steiermark -0.028902 0.067543 -0.428 0.669
L1.Tirol 0.158545 0.046511 3.409 0.001
L1.Vorarlberg 0.054649 0.042812 1.276 0.202
L1.Wien 0.218345 0.086903 2.513 0.012
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.236505 0.114124 2.072 0.038
L1.Burgenland 0.018524 0.056218 0.329 0.742
L1.Kärnten -0.069891 0.049424 -1.414 0.157
L1.Niederösterreich -0.074986 0.122585 -0.612 0.541
L1.Oberösterreich 0.019429 0.116116 0.167 0.867
L1.Salzburg 0.084017 0.064207 1.309 0.191
L1.Steiermark 0.336192 0.081758 4.112 0.000
L1.Tirol 0.461764 0.056300 8.202 0.000
L1.Vorarlberg 0.147587 0.051823 2.848 0.004
L1.Wien -0.154897 0.105192 -1.473 0.141
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.181737 0.136219 1.334 0.182
L1.Burgenland 0.041083 0.067102 0.612 0.540
L1.Kärnten -0.074747 0.058993 -1.267 0.205
L1.Niederösterreich 0.134092 0.146318 0.916 0.359
L1.Oberösterreich 0.018624 0.138597 0.134 0.893
L1.Salzburg 0.200401 0.076637 2.615 0.009
L1.Steiermark 0.115292 0.097587 1.181 0.237
L1.Tirol 0.057790 0.067200 0.860 0.390
L1.Vorarlberg 0.103105 0.061856 1.667 0.096
L1.Wien 0.228831 0.125558 1.823 0.068
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.559247 0.073983 7.559 0.000
L1.Burgenland -0.024091 0.036444 -0.661 0.509
L1.Kärnten -0.022734 0.032040 -0.710 0.478
L1.Niederösterreich 0.056601 0.079468 0.712 0.476
L1.Oberösterreich 0.310453 0.075274 4.124 0.000
L1.Salzburg 0.021798 0.041623 0.524 0.600
L1.Steiermark -0.037747 0.053001 -0.712 0.476
L1.Tirol 0.084988 0.036497 2.329 0.020
L1.Vorarlberg 0.111280 0.033595 3.312 0.001
L1.Wien -0.053748 0.068192 -0.788 0.431
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.149184 0.081587 0.165683 0.222917 0.076156 0.082804 0.013198 0.154008
Kärnten 0.149184 1.000000 0.040048 0.205690 0.179841 -0.062299 0.165231 0.027360 0.302511
Niederösterreich 0.081587 0.040048 1.000000 0.237254 0.081793 0.329299 0.140847 0.030002 0.293863
Oberösterreich 0.165683 0.205690 0.237254 1.000000 0.301674 0.262638 0.090213 0.060113 0.130577
Salzburg 0.222917 0.179841 0.081793 0.301674 1.000000 0.154647 0.053738 0.088736 0.009599
Steiermark 0.076156 -0.062299 0.329299 0.262638 0.154647 1.000000 0.101483 0.096868 -0.103711
Tirol 0.082804 0.165231 0.140847 0.090213 0.053738 0.101483 1.000000 0.161043 0.146753
Vorarlberg 0.013198 0.027360 0.030002 0.060113 0.088736 0.096868 0.161043 1.000000 -0.009747
Wien 0.154008 0.302511 0.293863 0.130577 0.009599 -0.103711 0.146753 -0.009747 1.000000